<template>
    <div>
        <top-bar></top-bar>
        <left-bar :datas='data'></left-bar>
        <div class="main" id="main">
            <div class="main-mains">
                <div class="main-content">
                    <div class="main-mains-top">
                        项目任务列表
                    </div>
                    <div class="main-top-nav">
                        <ul>
                            <router-link to="/projectTasks">
                                <li>项目任务列表</li>
                            </router-link>
                            <router-link to="/projectItem">
                                <li class="active">任务单元列表</li>
                            </router-link>
                        </ul>
                    </div>
                    <div class="screen clear">
                        <div class="fl" @click="screen()">筛选</div>
                    </div>
                    <div class="publicTable toLongTable">
                        <table class="head_table">
                            <tr>
                                <td width="4%">编号</td>
                                <td width='8%'>任务名称</td>
                                <td width='8%'>所属项目</td>
                                <td width='8%'>对应任务功能</td>
                                <td width='8%'>关联问卷</td>
                                <td width='8%'>委托产商</td>
                                <td width='8%'>创建时间</td>
                                <td width='8%'>启动时间</td>
                                <td width='8%'>截止时间</td>
                                <td width='8%'>排序</td>
                                <td width='12%'>操作</td>
                            </tr>
                        </table>
                        <el-scrollbar>
                            <table class="content_table">
                                <tr v-for="(item,index) in listData" :key="index" :class="{active:index%2==1}">
                                    <td width="4%">{{item.id}}</td>
                                    <td width='8%'>{{item.item_name}}</td>
                                    <td width='8%'>{{item.project_name}}</td>
                                    <td width='8%'>{{item.channel_name}}</td>
                                    <td width='8%'>{{item.surveys_name}}</td>
                                    <td width='8%'>{{item.company_name}}</td>
                                    <td width='8%'>{{item.create_time | times}}</td>
                                    <td width='8%'>{{item.begin_time | times}}</td>
                                    <td width='8%'>{{item.stop_time | times}}</td>
                                    <td width='8%'>
                                        <el-input v-model="item.ob" @blur="setOb($event,item.id,item.ob)"></el-input>
                                    </td>
                                    <td width='12%' class="operation">
                                        <span class="active" @click="copyUrl()">
                                            复制URl
                                        </span>
                                        <span class="active">
                                            编辑
                                        </span>
                                        <span class="active">
                                            查看
                                        </span>
                                        <span class="active">
                                            停用
                                        </span>
                                    </td>
                                </tr>
                            </table>
                        </el-scrollbar>
                    </div>
                    <div class="nodataTip" v-if="showNodataTip">
                        <i class="iconfont icon-zanwuneirong"></i>
                        <h5>暂无内容</h5>
                    </div>
                    <div class="orderBotom">
                        <div class="orderBotomRight">
                            <el-pagination @current-change="handleCurrentChange" :page-size="15" layout="total, prev, pager, next" :total='totalnum'>
                            </el-pagination>
                        </div>
                    </div>
                </div>
            </div>
            <div class="system-menban" v-if="search ">
            </div>
            <div class="systemPopup" v-if="search">
                <div class="topTitle">
                    <span>筛选项目任务</span>
                    <i class="el-icon-close system-icon" @click="hideSystemPopup"></i>
                </div>
                <div class="systemPopup-con">
                    <div class="systemPopup-cons clear">
                        <div class="fl">时间</div>
                        <div class="fl sel">
                            <el-date-picker v-model="time" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
                            </el-date-picker>
                        </div>
                    </div>
                    <div class="systemPopup-cons clear">
                        <div class="fl">关键词搜索</div>
                        <div class="fl sel">
                            <el-input placeholder="请输入任务名称/厂商/任务单元名称" v-model.trim="keyword" clearable>
                            </el-input>
                        </div>
                    </div>
                    <div class="systemPopup-btn clear">
                        <div class="fl" @click="searchs()">确认</div>
                        <div class="fl" @click="hideSystemPopup">取消</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>


<script>
import leftBar from "@/components/leftBar";
import topBar from "@/components/topBar";
import project from "@/api/saleProject";
export default {
  components: {
    leftBar,
    topBar
  },
  data() {
    return {
      data: "projectTasks",
      pages: 1,
      listData: [],
      name: "",
      business: "",
      totalnum: 0,
      showNodataTip: false,
      search: false,
      keyword: "",
      time: [],
      taskType: "",
      taskId: "",
      taskTitle: ""
    };
  },
  methods: {
    addElement(obj) {
      var parent = document.getElementById(obj);
      var text = document.createElement("textarea");
      text.setAttribute("id", "textareas");
      text.value = "动态添加";
      parent.appendChild(text);
      console.log(text);
      text.select(); // 选中文本
      document.execCommand("copy");
    },
    copyUrl() {
      this.addElement("main");
    },
    setOb(e, id, num) {
      if (!event.target.value) {
        return false;
      }
      const options = {
        spiid: id,
        ob: event.target.value
      };
      project.setOb(options).then(res => {
        if (res.code == 1) {
          this.$message({
            showClose: true,
            message: "设置成功！",
            type: "success"
          });
          this.getList();
        }
      });
    },
    searchs() {
      this.pages = 1;
      this.getList();
    },
    handleCurrentChange(val) {
      this.pages = val;
      this.getList();
    },
    getList() {
      this.showNodataTip = false;
      let options = {};
      if (this.time == "" || this.time == null) {
        options = {
          page: this.pages,
          key_word: this.keyword,
          from_time: "",
          to_time: ""
        };
      } else {
        options = {
          page: this.pages,
          key_word: this.keyword,
          from_time: this.time[0],
          to_time: this.time[0]
        };
      }
      project.projectItem(options).then(res => {
        if (res.code == 1) {
          this.search = false;
          this.listData = res.data.data;
          this.totalnum = res.data.total;
          if (!res.data.total) {
            this.showNodataTip = true;
          }
        }
      });
    },
    screen() {
      this.search = true;
    },
    hideSystemPopup() {
      this.search = false;
    }
  },
  mounted() {
    this.getList();
  },
  filters: {
    times(value) {
      var time = new Date(value * 1000);
      var month =
        time.getMonth() + 1 > 9
          ? time.getMonth() + 1
          : "0" + (time.getMonth() + 1);
      var data = time.getDate() > 9 ? time.getDate() : "0" + time.getDate();
      var hour = time.getHours() > 9 ? time.getHours() : "0" + time.getHours();
      var minutes =
        time.getMinutes() > 9 ? time.getMinutes() : "0" + time.getMinutes();
      var second =
        time.getSeconds() > 9 ? time.getSeconds() : "0" + time.getSeconds();
      var times =
        time.getFullYear() +
        "-" +
        month +
        "-" +
        data +
        " " +
        hour +
        ":" +
        minutes +
        ":" +
        second;
      return times;
    }
  }
};
</script>

<style>
</style>
